
class HandleRepeatClass {
    constructor(fn, delay = 1000) {
        this.fn = fn;
        this.delay = delay
        this.lastCall = 0;
    }

    throttle() {
        const _this = this
        return function(...args) {
            const now = Date.now();
            if (now - _this.lastCall >= _this.delay) {
                _this.fn.apply(_this.context, args)
                _this.lastCall = now;
            }
        }
    }

}


function getThrottle(fn, wait = 1000) {
    const context = this;
    return new HandleRepeatClass(fn.bind(context), wait).throttle()
}

export {
    getThrottle
}
